// ==UserScript== // @name 【高教在线刷课助手】|| 自动执行,移除防止暂停,自动跳转下一节 // @namespace http://tampermonkey.net/ // @version 0.0.1 // @description 高教在线课程自动挂机,当前脚本支持课程视频播放完成,自动跳转下一小节,章节测试自动跳过,后台播放防止视频暂停。 // @author Sweek // @match *://*.cqooc.com/* // @license GPLv3 // @icon https://www.sweek.top/api/preview/avatar.jpg // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @require https://code.jquery.com/jquery-2.1.4.min.js // @grant unsafeWindow // @grant GM_getResourceText // ==/UserScript== /* 窗口初始化 */ /* 窗口初始化 */ /* 窗口初始化 */ function initPopup() { // 创建 CSS 样式 const popCSs = ` #my-window { position: fixed; top: 10px; left: 20px; width: 400px; height: 600px; background: rgb(255, 255, 255); color: white; font-size: 14px; border-radius: 5px; z-index: 9999; display: flex; flex-direction: column; user-select: none; font-family: 'fangsong'; border: 1px solid rgb(71, 158, 130); overflow: hidden; } #window-header { height: 50px; padding: 0 10px; background: rgb(71, 158, 130); cursor: grab; display: flex; justify-content: space-between; align-items: center; border-radius: 5px 5px 0 0; .window-header-title { font-size: 16px; font-weight: bold; font-family: 'fangsong'; } } #restore-btn { cursor: pointer; font-size: 16px; background: none; border: none; color: #444; height:20px; width:30px; text-align: center; line-height: 20px; background: #fff; border-radius: 5px; padding: 0 5px; } #restore-btn:hover { background: rgb(71, 158, 130); border: 1px solid #fff; color: #fff; } .tab { display: inline-block; padding: 5px 10px; cursor: pointer; background: #888; text-align: center; font-weight: bold; } .tab.active { background: #444; } #window-content { flex: 1; padding: 8px; overflow: auto; } #my-window.minimized { height: 50px; overflow: hidden; } #tab-container { display: block; width: 100%; background: #ddd; display: grid; grid-template-columns: repeat(2, 1fr); padding: 6px 8px; } #window-content { display: block; background: #fff; } #my-window.minimized #window-content, #my-window.minimized #tab-container { display: none; } #taskCountContent { background: #fff; border: 1px solid #ccc; border-radius: 5px; height: 100%; overflow-y: auto; color: #333; line-height: 20px; padding: 5px; } #taskLogsContent { background: #222; border: 1px solid #ccc; border-radius: 2px; height: 100%; overflow-y: auto; color: #fff; line-height: 20px; padding: 5px; } `; // 添加 CSS 样式 const style = document.createElement("style"); style.innerHTML = popCSs; document.head.appendChild(style); // 创建窗口元素 const popHtml = `
Sweek高教在线刷课助手[0.0.1]
页面任务 执行日志
当前任务数: 0
`; const myWindow = document.createElement("div"); myWindow.id = "my-window"; myWindow.innerHTML = popHtml; document.body.appendChild(myWindow); // 绑定最小化按钮事件 document.getElementById("restore-btn").addEventListener("click", () => { myWindow.classList.toggle("minimized"); }); // 处理拖动窗口 let isDragging = false; let offsetX = 0; let offsetY = 0; document.getElementById("window-header").addEventListener("mousedown", (e) => { isDragging = true; offsetX = e.clientX - myWindow.offsetLeft; offsetY = e.clientY - myWindow.offsetTop; }); document.addEventListener("mousemove", (e) => { if (isDragging) { let x = e.clientX - offsetX; let y = e.clientY - offsetY; // 限制窗口不能拖出屏幕 let maxX = window.innerWidth - myWindow.offsetWidth; let maxY = window.innerHeight - myWindow.offsetHeight; x = Math.max(0, Math.min(x, maxX)); y = Math.max(0, Math.min(y, maxY)); myWindow.style.left = `${x}px`; myWindow.style.top = `${y}px`; } }); document.addEventListener("mouseup", () => { isDragging = false; }); // 绑定 Tab 切换事件 document.querySelectorAll(".tab").forEach(tab => { tab.addEventListener("click", () => { document.querySelectorAll(".tab").forEach(el => el.classList.remove("active")); tab.classList.add("active"); document.getElementById("taskCountContent").style.display = "none"; document.getElementById("taskLogsContent").style.display = "none"; if (tab.dataset.tab === "taskCount") { document.getElementById("taskCountContent").style.display = "block"; } else { document.getElementById("taskLogsContent").style.display = "block"; } }); }); } function destroyPopup() { const myWindow = document.getElementById("my-window"); if (myWindow) { myWindow.remove(); // 移除窗口 } const styleTags = document.querySelectorAll("style"); styleTags.forEach(style => { if (style.innerHTML.includes("#my-window")) { style.remove(); // 移除添加的 CSS 样式 } }); document.removeEventListener("mousemove", moveHandler); document.removeEventListener("mouseup", upHandler); // console.log("窗口已销毁"); } /* 课程处理方法 */ /* 课程处理方法 */ /* 课程处理方法 */ let taskQueue = []; // 任务队列 const testDealEvent = new Event("testRedeal", { bubbles: false, cancelable: false }); // 处理视频 function handleVideo(Dom) { return new Promise((resolve) => { const playButton = Dom.querySelector(".dplayer-mobile-play"); // 获取播放按钮 const video = Dom.querySelector("video"); // 获取视频元素 if (!video) { addLog("未找到视频元素"); return resolve(); } let playAttempted = false; // 是否尝试过播放 // 监听视频播放时的进度 video.addEventListener("timeupdate", () => { const currentTime = video.currentTime; // 当前播放时间 const duration = video.duration; // 视频总时长 const playbackRate = video.playbackRate; // 播放倍速 // 生成显示进度的内容 const val1 = currentTime; // 当前播放时间 const val2 = duration; // 视频总时长 setProgress(val1, val2, playbackRate, 'video'); // 设置显示播放进度 }); function preventPause() { video.onpause = () => { // addLog("视频暂停,1秒后重新播放"); setTimeout(() => { if (video.paused) { video.play().catch((error) => { addLog(`重新播放失败: ${error}`); }); } }, 500); // 0.5秒后重新播放 }; } function checkPlayback() { setTimeout(() => { if (!video.paused) { addLog("视频已成功播放"); return; } addLog("播放按钮点击无效,尝试直接调用 video.play()"); video.muted = true; // 静音播放,防止浏览器限制 video.play().catch((error) => { addLog(`直接播放失败: ${error}`); }); }, 500); // 延迟检查,确保点击后有时间触发播放 } if (playButton) { addLog("找到播放按钮,尝试点击播放"); playButton.click(); playAttempted = true; checkPlayback(); // 延迟检查播放情况 } if (!playAttempted) { addLog("未找到播放按钮,尝试直接调用 video.play()"); video.muted = true; video.play().catch((error) => { addLog(`直接播放失败: ${error}`); }); } // 阻止视频暂停 preventPause(); // 监听视频播放完成事件 video.onended = () => { addLog("视频播放完成"); // 清理事件监听和状态 video.onended = null; // 移除事件监听 video.onpause = null; // 移除暂停监听 resolve(); // 完成当前视频任务 }; }); } // 处理PDF function handlePDF(Dom) { return new Promise((resolve) => { const interval = setInterval(() => { const headerBox = document.querySelector(".header-box"); if (headerBox) { const text = headerBox.innerText; if (!text.includes("完成倒计时")) { clearInterval(interval); // 停止轮询 resolve(); // 任务完成,调用 resolve } } }, 1000); // 每秒检查一次 }); } // 获取课程内容类型 function getCourseContentType(Dom) { // 获取DOM元素的HTML内容 const htmlContent = Dom.innerHTML || Dom.outerHTML; // 判断Dom中是否包含